home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / TextPertDK#1 / MPW C Sources & Examples.image / Example2 / AppleScan.c next >
Text File  |  1991-10-25  |  12KB  |  417 lines

  1. /*
  2.         This file implements the calls that are defined in the
  3.         APPLE SCANNER TECHNICAL REFERENCE MANUAL.
  4.         
  5.         CAUTION: These calls are implemented for MPW 3.X or Higher.
  6.                             For MPW version 2.XX, the calls must be checked.
  7.         
  8.         The calls defined in the manual are implemented by DEVICE MANAGER CALLS,
  9.         and are the standard calls that Apple has defined for a scanner.
  10.         
  11. */
  12.  
  13. #include <devices.h>
  14. #include <files.h>
  15. #include <quickdraw.h>
  16. #include <string.h>
  17.  
  18. #include "AppleScan.h"
  19.  
  20.         /* Opening and closing the driver */
  21.  
  22.     /* ScOpen                                                OpenDriver   */
  23.     /* ScClose                                            Closedriver */
  24.  
  25.         /* Getting Standard Features */
  26.  
  27. #define    ScGetStdFeaturesStCall        2
  28. #define    ScGetResStCall                        3
  29. #define    ScGetHalfTonesStCall            4
  30.  
  31.         /* Setting Scan Area */
  32.  
  33. #define    ScSetScanAreaCtlCall            2
  34.  
  35.         /* Reading Scanned Data */
  36.  
  37.     /* ScDoScan                                            ReadCall */
  38. #define    ScAbortScanCtlCall                1
  39.  
  40.         /* Getting Advanced Features calls' code */
  41.     
  42. #define    ScGetAdvFeaturesStCall        5
  43. #define    ScSetHtPatternCtlCall            4
  44.  
  45. #define    ScSetGroup3CtlCall                5
  46. #define    ScSetNoHomeCtlCall                6
  47. #define    ScSetLampCtlCall                    7
  48. #define    ScSetGrayMapCtlCall                8
  49. #define    ScSetThresHoldCtlCall            9
  50. #define    ScSetWaitButtonCtlCall        10
  51.  
  52. /***************************************************************************************/
  53. /******************************* ROUTINE IMPLEMENTATION ********************************/
  54. /***************************************************************************************/
  55.     /* Opening and Closing the standard driver */
  56. /***************************************************************************************/
  57. pascal OSErr ScOpen(Str255 Nombre, short *RefNum)   /* Variation ; Also receives the name */
  58.     /* Opens the driver and reset the scanner to it default values. */
  59.  
  60. {
  61. return OpenDriver(Nombre, RefNum);
  62. }
  63.     
  64. /***************************************************************************************/
  65. pascal OSErr ScClose(short RefNum)
  66.     /* Closes the driver and releases the scanner. */
  67. {
  68. return CloseDriver(RefNum);
  69. }
  70.     
  71.     
  72.     /* Getting Standard Features */
  73. /***************************************************************************************/
  74. pascal OSErr ScGetStdFeatures(short RefNum,
  75.                                                             ScStdFeaturesPtr    stdFeaturesPtr,
  76.                                                             short    Length)
  77.     /* Gives the user a complete description of the features of the scanner, following the 
  78.       structure described in the stdFeaturesRec returned. */
  79. {
  80. char                        NullStr[10];
  81. ParamBlockRec        ParamBl;
  82.  
  83. ParamBl.cntrlParam.ioCompletion = nil;
  84. ParamBl.cntrlParam.ioCRefNum = RefNum;
  85. strcpy(NullStr, "");
  86. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  87.  
  88. ParamBl.cntrlParam.csCode = ScGetStdFeaturesStCall;
  89. ((long *)ParamBl.cntrlParam.csParam)[0] = (long)stdFeaturesPtr;
  90. /* will take position 0 and 1 of the short array */
  91. ParamBl.cntrlParam.csParam[2] = Length;
  92.  
  93. return (PBStatus(&ParamBl, false));
  94.  
  95. }
  96.  
  97.  
  98. /***************************************************************************************/
  99. pascal OSErr ScGetRes(short RefNum,
  100.                                             short            CompType,
  101.                                             ScResPtr    ResPtr)
  102.     
  103.     /* Returns an array with the resolutions supported by the scanner.
  104.       The number of Resolutions supported by the scanner is defined in the stdFeaturesRec.  */
  105. {
  106. char                        NullStr[10];
  107. ParamBlockRec        ParamBl;
  108.  
  109. ParamBl.cntrlParam.ioCompletion = nil;
  110. ParamBl.cntrlParam.ioCRefNum = RefNum;
  111. strcpy(NullStr, "");
  112. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  113.  
  114. ParamBl.cntrlParam.csCode = ScGetResStCall;
  115. ParamBl.cntrlParam.csParam[0] = CompType;
  116. ((long *)ParamBl.cntrlParam.csParam)[1] = (long)ResPtr;
  117. /* will take position 1 and 2 of the short array */
  118.  
  119. return (PBStatus(&ParamBl, false));
  120.  
  121. }
  122.  
  123.  
  124. /***************************************************************************************/
  125. pascal OSErr ScGetHalfTones(short RefNum,
  126.                                                 short            CompType,
  127.                                                 ScHalfTonePtr    HalfTonePtr)
  128.  
  129.     /* Returns the list of supported halftone patterns.
  130.       This list has the structure described in the schalftone array. */
  131. {
  132. char                        NullStr[10];
  133. ParamBlockRec        ParamBl;
  134.  
  135. ParamBl.cntrlParam.ioCompletion = nil;
  136. ParamBl.cntrlParam.ioCRefNum = RefNum;
  137. strcpy(NullStr, "");
  138. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  139.  
  140. ParamBl.cntrlParam.csCode = ScGetHalfTonesStCall;
  141. ParamBl.cntrlParam.csParam[0] = CompType;
  142. ((long *)ParamBl.cntrlParam.csParam)[1] = (long)HalfTonePtr;
  143. /* will take position 1 and 2 of the short array */
  144.  
  145. return (PBStatus(&ParamBl, false));
  146.  
  147. }
  148.       
  149.       
  150.  
  151.     /* Setting Scan Area */
  152. /***************************************************************************************/
  153. pascal OSErr ScSetScanArea(short RefNum,
  154.                                                    ScScanAreaPtr ScanAreaPtr)
  155.     
  156.     /* Sets the area to scan, and also the parameters to use in the scan of that area. */
  157. {
  158. char                        NullStr[10];
  159. ParamBlockRec        ParamBl;
  160.  
  161. ParamBl.cntrlParam.ioCompletion = nil;
  162. ParamBl.cntrlParam.ioCRefNum = RefNum;
  163. strcpy(NullStr, "");
  164. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  165.  
  166. ParamBl.cntrlParam.csCode = ScSetScanAreaCtlCall;
  167. ((long *)ParamBl.cntrlParam.csParam)[0] = (long)ScanAreaPtr;
  168. /* will take position 1 and 2 of the short array */
  169.  
  170. return (PBControl(&ParamBl, false));
  171.  
  172. }
  173.     
  174.     
  175.  
  176.     /* Reading Scanned Data */
  177. /***************************************************************************************/
  178. pascal OSErr ScDoScan(short RefNum,
  179.                                           Ptr        Buffer,
  180.                                           long    *Count,
  181.                                           short    Unused,
  182.                                           short    ByteWidth,
  183.                                           short    RowBytes)
  184.     
  185.     /* Starts scan and returns data following the parameters previously set. */
  186. {
  187. char                        NullStr[10];
  188. ParamBlockRec        ParamBl;
  189. short                        Error;
  190.  
  191. ParamBl.cntrlParam.ioCompletion = nil;
  192. ParamBl.cntrlParam.ioCRefNum = RefNum;
  193. strcpy(NullStr, "");
  194. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  195.  
  196. ParamBl.ioParam.ioReqCount = *Count;
  197. ParamBl.ioParam.ioBuffer = Buffer;
  198. ParamBl.ioParam.ioPosMode = Unused;
  199. ParamBl.ioParam.ioPosOffset = ((long)ByteWidth << 16) | (long)RowBytes;
  200.  
  201. Error = PBRead(&ParamBl, false);
  202.  
  203. *Count = ParamBl.ioParam.ioActCount;
  204.  
  205. return (Error);
  206.  
  207. }
  208.     
  209.     
  210. /***************************************************************************************/
  211. pascal OSErr ScAbortScan(short RefNum)
  212.  
  213.     /* Aborts the scan in progress. Is the only call that the scanner
  214.       will answer to while a scan is being done.        */
  215. {
  216. char                        NullStr[10];
  217. ParamBlockRec        ParamBl;
  218.  
  219. ParamBl.cntrlParam.ioCompletion = nil;
  220. ParamBl.cntrlParam.ioCRefNum = RefNum;
  221. strcpy(NullStr, "");
  222. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  223.  
  224. ParamBl.cntrlParam.csCode = ScAbortScanCtlCall;
  225.  
  226. return (PBControl(&ParamBl, false));
  227.  
  228. }
  229.  
  230.  
  231.  
  232.     /* Getting Advanced Features */
  233. /***************************************************************************************/
  234. pascal OSErr ScGetAdvFeatures(short RefNum,
  235.                           ScAdvFeaturesPtr    AdvFeaturesPtr,
  236.                           short                            Length)
  237.     
  238.     /* Gives the user avdanced features of the scanner. Returns a
  239.       handle to ScAdvFeaturesRec. If a scanner doesn't support this call,
  240.       a statuserr value of -18 is returned. */
  241. {
  242. char                        NullStr[10];
  243. ParamBlockRec        ParamBl;
  244.  
  245. ParamBl.cntrlParam.ioCompletion = nil;
  246. ParamBl.cntrlParam.ioCRefNum = RefNum;
  247. strcpy(NullStr, "");
  248. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  249.  
  250. ParamBl.cntrlParam.csCode = ScGetAdvFeaturesStCall;
  251. ((long *)ParamBl.cntrlParam.csParam)[0] = (long)AdvFeaturesPtr;
  252. /* will take position 0 and 1 of the short array */
  253. ParamBl.cntrlParam.csParam[2] = Length;
  254.  
  255. return (PBStatus(&ParamBl, false));
  256.  
  257. }
  258.       
  259.       
  260. /***************************************************************************************/
  261. pascal OSErr ScSetHtPattern(short            RefNum,
  262.                                                         ScPatPtr    PatPtr)
  263.  
  264.     /* Sets the downloadable halftone pattern */
  265. {
  266. char                        NullStr[10];
  267. ParamBlockRec        ParamBl;
  268.  
  269. ParamBl.cntrlParam.ioCompletion = nil;
  270. ParamBl.cntrlParam.ioCRefNum = RefNum;
  271. strcpy(NullStr, "");
  272. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  273.  
  274. ParamBl.cntrlParam.csCode = ScSetHtPatternCtlCall;
  275. ((long *)ParamBl.cntrlParam.csParam)[0] = (long)PatPtr;
  276. /* will take position 1 and 2 of the short array */
  277.  
  278. return (PBControl(&ParamBl, false));
  279.  
  280. }
  281.     
  282.     
  283. /***************************************************************************************/
  284. pascal OSErr ScSetGroup3(short RefNum,
  285.                                                  Boolean    CompressOn)
  286.  
  287.     /* Enables and disables data compression in data returned by the scanner.
  288.       The compression used is Group III, 1-dimensional standard FAX encoding. */
  289. {
  290. char                        NullStr[10];
  291. ParamBlockRec        ParamBl;
  292.  
  293. ParamBl.cntrlParam.ioCompletion = nil;
  294. ParamBl.cntrlParam.ioCRefNum = RefNum;
  295. strcpy(NullStr, "");
  296. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  297.  
  298. ParamBl.cntrlParam.csCode = ScSetGroup3CtlCall;
  299. ParamBl.cntrlParam.csParam[0] = ((CompressOn) ? (1) : (0));
  300.  
  301. return (PBControl(&ParamBl, false));
  302.  
  303. }
  304.       
  305.       
  306. /***************************************************************************************/
  307. pascal OSErr ScSetNoHome(short RefNum,
  308.                                                  Boolean    NoHome)
  309.  
  310.     /* This function control whether or not the carriage assembly returns
  311.       to the home position after scanning. */
  312. {
  313. char                        NullStr[10];
  314. ParamBlockRec        ParamBl;
  315.  
  316. ParamBl.cntrlParam.ioCompletion = nil;
  317. ParamBl.cntrlParam.ioCRefNum = RefNum;
  318. strcpy(NullStr, "");
  319. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  320.  
  321. ParamBl.cntrlParam.csCode = ScSetNoHomeCtlCall;
  322. ParamBl.cntrlParam.csParam[0] = ((NoHome) ? (1) : (0));
  323.  
  324. return (PBControl(&ParamBl, false));
  325.  
  326. }
  327.       
  328.       
  329. /***************************************************************************************/
  330. pascal OSErr ScSetLamp(short RefNum,
  331.                                            Boolean    LampOn)
  332.  
  333.     /* This call turns the fluorescent lamp On and Off. */
  334. {
  335. char                        NullStr[10];
  336. ParamBlockRec        ParamBl;
  337.  
  338. ParamBl.cntrlParam.ioCompletion = nil;
  339. ParamBl.cntrlParam.ioCRefNum = RefNum;
  340. strcpy(NullStr, "");
  341. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  342.  
  343. ParamBl.cntrlParam.csCode = ScSetLampCtlCall;
  344. ParamBl.cntrlParam.csParam[0] = ((LampOn) ? (1) : (0));
  345.  
  346. return (PBControl(&ParamBl, false));
  347.  
  348. }
  349.     
  350.     
  351. /***************************************************************************************/
  352. pascal OSErr ScSetGrayMap(short RefNum,
  353.                                               short    GrayMap)
  354.  
  355.     /* Sets the gray map curve used while scanning. */
  356. {
  357. char                        NullStr[10];
  358. ParamBlockRec        ParamBl;
  359.  
  360. ParamBl.cntrlParam.ioCompletion = nil;
  361. ParamBl.cntrlParam.ioCRefNum = RefNum;
  362. strcpy(NullStr, "");
  363. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  364.  
  365. ParamBl.cntrlParam.csCode = ScSetGrayMapCtlCall;
  366. ParamBl.cntrlParam.csParam[0] = GrayMap;
  367.  
  368. return (PBControl(&ParamBl, false));
  369.  
  370. }
  371.     
  372.     
  373. /***************************************************************************************/
  374. pascal OSErr ScSetThresHold(short RefNum,
  375.                                                         short    Threshold)
  376.  
  377.     /* Sets the AutoBackground threshold level. */
  378. {
  379. char                        NullStr[10];
  380. ParamBlockRec        ParamBl;
  381.  
  382. ParamBl.cntrlParam.ioCompletion = nil;
  383. ParamBl.cntrlParam.ioCRefNum = RefNum;
  384. strcpy(NullStr, "");
  385. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  386.  
  387. ParamBl.cntrlParam.csCode = ScSetThresHoldCtlCall;
  388. ParamBl.cntrlParam.csParam[0] = Threshold;
  389.  
  390. return (PBControl(&ParamBl, false));
  391.  
  392. }
  393.     
  394.     
  395. /***************************************************************************************/
  396. pascal OSErr ScSetWaitButton(short RefNum,
  397.                                                          Boolean    WaitButton)
  398.  
  399.     /* This function controls if the scan will begin after a
  400.       DoScan command is send or if the scanner will wait for the
  401.       button it has to be pressed before beginning to scan. */        
  402. {
  403. char                        NullStr[10];
  404. ParamBlockRec        ParamBl;
  405.  
  406. ParamBl.cntrlParam.ioCompletion = nil;
  407. ParamBl.cntrlParam.ioCRefNum = RefNum;
  408. strcpy(NullStr, "");
  409. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  410.  
  411. ParamBl.cntrlParam.csCode = ScSetWaitButtonCtlCall;
  412. ParamBl.cntrlParam.csParam[0] = ((WaitButton) ? (1) : (0));
  413.  
  414. return (PBControl(&ParamBl, false));
  415.  
  416. }
  417.